package utils

type Deque struct {
	items []int
}

func (d *Deque) IsEmpty() bool {
	return len(d.items) == 0
}

func (d *Deque) AddFront(item int) {
	d.items = append([]int{item}, d.items...)
}

func (d *Deque) AddBack(item int) {
	d.items = append(d.items, item)
}

func (d *Deque) RemoveFront() int {
	if d.IsEmpty() {
		panic("deque is empty")
	}
	item := d.items[0]
	d.items = d.items[1:]
	return item
}

func (d *Deque) RemoveBack() int {
	if d.IsEmpty() {
		panic("deque is empty")
	}
	index := len(d.items) - 1
	item := d.items[index]
	d.items = d.items[:index]
	return item
}

func (d *Deque) Front() int {
	if d.IsEmpty() {
		panic("deque is empty")
	} else {
		return d.items[0]
	}
}

func (d *Deque) Back() int {
	if d.IsEmpty() {
		panic("deque is empty")
	} else {
		return d.items[len(d.items)-1]
	}
}